package com.example.jw_web.Control;

import com.example.jw_web.Mapper.HomePageDao;
import com.example.jw_web.pojo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Member;
import java.util.List;

@RestController
@Slf4j
@CrossOrigin(origins = "*")  //允许后端访问
public class homePage {

    @Autowired
    HomePageDao homePages;

    //工作室近况
    @GetMapping("/recently")
       public Result getRecently()
    {
       log.info("工作室近况");
        List<activeDao> activeDaos= homePages.getitems();

        return Result.success(activeDaos);
    }

    //主页团队成员
    @GetMapping("/members")
    public Result getMembers()
    {
        log.info("获取团队成员信息");
        List<member> members=homePages.getMembers();
        return Result.success(members);
    }

    //主页作品展示
    @GetMapping("/fineWorks")
    public  Result getFineWorks()
    {
        log.info("主页作品展示");
        List<Works> works=homePages.getWorks();
        return  Result.success(works);
    }

    //主页简介
    @GetMapping("/introduce")
    public Result getIntroduce()
    {
        log.info("简介");
       List<introduce> introduces=homePages.getintroduces();
        return  Result.success(introduces);
    }

    //成员分布
    @GetMapping("/teammember")
    public  Result getTeammember()
    {
        log.info("成员分布");
        List<member> members=homePages.getMembers();
        return Result.success(members);
    }

    //作品展示
    @GetMapping("/works")
     public Result getWorks()
    {
        log.info("作品展示");
        List<Works> works=homePages.getWorks();
        return  Result.success(works);
    }

    //作品分类
    @GetMapping("/worksByCategory")
    public Result sort( String sort)
    {
        log.info("作品分类");
        List<Works> works=homePages.getSortWorks(sort);
        return Result.success(works);
    }

    //作品项目名搜索
    @GetMapping ("/researchworks")
    public Result researchworks(String title)
    {
        log.info("作品根据项目名字搜素");
        List<Works> works =homePages.getresearchworks(title);
        return Result.success(works);
    }

    //成员搜索
    @PostMapping("/limitMembers")
    public Result getTeamMembersInfo(@RequestBody memberRequest memberRequest){

        log.info("成员搜索");

        List<String> jobs = memberRequest.getDirection();
        List<String> times =memberRequest.getTime();
        List<member> members = homePages.getMembersByJobAndTime(jobs,times);
        System.out.println("成员搜索结果"+members);
        return Result.success(members);
    }

}
